package designPattern.filter;

import java.util.ArrayList;
import java.util.List;

public class FilterChain {
	List<Filter> filters = new ArrayList<Filter>();// 数组形式的责任链，他通过一个index来驱动请求向下执行

	public FilterChain add(Filter f) {
		filters.add(f);
		return this; // 返回this的好处是：可以链式编程
	}

	public String doFilter(String msg) {
		for (Filter f : filters) {
			msg=f.doFilter(msg);
		}
		return msg;
	}
}
